import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { resolve } from 'path'

function pathResolve(dir: string) {
  return resolve(process.cwd(), '.', dir)
}
export default defineConfig({
  base: './',
  define: {
    __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'false',
  },
  resolve: {
    // 配置别名
    alias: [{ find: '@', replacement: pathResolve('src') + '/' }],
  },
  plugins: [
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    vue(),
  ],
  build: {
    rollupOptions: {
      external: ['/api/render']
    }
  },
  server: {
    port: 9999,
    open: true,
    proxy: {
      '/api': {
        target: 'http://127.0.0.1:9789',
        rewrite: (path) => path.replace(/^\/api/, ""),
        changeOrigin: true
      },
    },
  },
})
